#include <Windows.h>
#include <extend.h>

#define ID_YES 6

extern HANDLE _hInstance;

//----------------------------------------------------------------------------//

void MsgInfo( LPSTR szMsg, LPSTR szTitle )
{
   MessageBox( 0, szMsg, szTitle, MB_ICONINFORMATION );
}

//----------------------------------------------------------------------------//

void MsgAlert( LPSTR szMsg, LPSTR szTitle )
{
   MessageBox( 0, szMsg, szTitle, MB_ICONEXCLAMATION );
}

//----------------------------------------------------------------------------//

void MsgStop( LPSTR szMsg, LPSTR szTitle )
{
   MessageBox( 0, szMsg, szTitle, MB_ICONSTOP );
}

//----------------------------------------------------------------------------//

BOOL MsgYesNo( LPSTR szMsg, LPSTR szTitle )
{
   return MessageBox( 0, szMsg, szTitle, MB_ICONQUESTION | MB_YESNO ) == ID_YES;
}

//----------------------------------------------------------------------------//

BOOL MsgNoYes( LPSTR szMsg, LPSTR szTitle )
{
   return MessageBox( 0, szMsg, szTitle,
                      MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2  ) == ID_YES;
}

//----------------------------------------------------------------------------//

void ValToChar( PCLIPVAR v )  // stores the result at _eval
{
   BYTE buffer[ 10 ];

   switch( v->wType )
   {
      case VT_NIL:
           _retc( "nil" );
           break;

      case VT_DATE:
           _retc( _pard( 1 ) );
           break;

      case VT_FLOAT:
      case VT_NUMERIC:
           _str( _parnl( 1 ), buffer );
           _retc( buffer );
           break;

      case VT_LOGICAL:
           _retc( IF( _parl( 1 ), ".t.", ".f." ) );
           break;

      default:
           _retc( _parc( 1 ) );
           break;
   }
}

//----------------------------------------------------------------------------//

CLIPPER MSGABOUT()
{
   HICON hIcon   = LoadIcon( _hInstance, MAKEINTRESOURCE( 1 ) );
   LPSTR szTitle = ISCHAR( 2 ) ? _parc( 2 ): "About";
   LPSTR szMsg;

   if( _param( 1, -1 ) )
   {
        ValToChar( _param( 1, -1 ) );
        szMsg = _parc( -1 );
   }
   else
        szMsg = "Application Information";

   ShellAbout( GetActiveWindow(), szMsg, szTitle, hIcon ? hIcon: 0 );
}

//----------------------------------------------------------------------------//

CLIPPER MSGINFO()
{
   LPSTR szMsg;

   if( _pcount() > 0 )
   {
      if( _ischar( 1 ) )
         szMsg = _parc( 1 );
      else
      {
         ValToChar( _param( 1, 0xFFFF ) );
         szMsg = _parc( -1 );     // access _eval
      }
   }
   else
      szMsg = "";

   MsgInfo( szMsg, IF( _pcount() > 1, _parc( 2 ), "Information" ) );
}

//----------------------------------------------------------------------------//

CLIPPER MSGALERT()
{
   LPSTR szMsg;

   if( _pcount() > 0 )
   {
      if( _ischar( 1 ) )
         szMsg = _parc( 1 );
      else
      {
         ValToChar( _param( 1, 0xFFFF ) );
         szMsg = _parc( -1 );     // access _eval
      }
   }
   else
      szMsg = "";

   MsgAlert( szMsg, IF( _pcount() > 1, _parc( 2 ), "Alert" ) );
}

//----------------------------------------------------------------------------//

CLIPPER MSGSTOP()
{
   LPSTR szMsg;

   if( _pcount() > 0 )
   {
      if( _ischar( 1 ) )
         szMsg = _parc( 1 );
      else
      {
         ValToChar( _param( 1, 0xFFFF ) );
         szMsg = _parc( -1 );     // access _eval
      }
   }
   else
      szMsg = "";

   MsgStop( szMsg, IF( _pcount() > 1, _parc( 2 ), "Stop" ) );
}

//----------------------------------------------------------------------------//

CLIPPER MSGYESNO()
{
   LPSTR szMsg;

   if( _pcount() > 0 )
   {
      if( _ischar( 1 ) )
         szMsg = _parc( 1 );
      else
      {
         ValToChar( _param( 1, 0xFFFF ) );
         szMsg = _parc( -1 );     // access _eval
      }
   }
   else
      szMsg = "";

   _retl( MsgYesNo( szMsg, IF( _pcount() > 1, _parc( 2 ), "Please, select" ) ) );
}

//----------------------------------------------------------------------------//

CLIPPER MSGNOYES()
{
   LPSTR szMsg;

   if( _pcount() > 0 )
   {
      if( _ischar( 1 ) )
         szMsg = _parc( 1 );
      else
      {
         ValToChar( _param( 1, 0xFFFF ) );
         szMsg = _parc( -1 );     // access _eval
      }
   }
   else
      szMsg = "";

   _retl( MsgNoYes( szMsg, IF( _pcount() > 1, _parc( 2 ), "Please, select" ) ) );
}

//----------------------------------------------------------------------------//
